# Create your models here.
# operation/py

from datetime import datetime

from django.db.models import *

from course.models import Course
from users.models import User


class UserAsk(Model):
    is_del = IntegerField(default=0)
    name = CharField('姓名', max_length=20)
    mobile = CharField('手机', max_length=11)
    course_name = CharField('课程名', max_length=50)
    add_time = DateTimeField('添加时间', default=datetime.now)

    class Meta:
        verbose_name = '用户咨询'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class UserMessage(Model):
    is_del = IntegerField(default=0)
    MESSAGE_TYPE = (
        (1, '平台'),
        (2, '机构'),
        (3, '讲师'),
    )
    user = IntegerField('接受用户', default=0)
    message = CharField('消息内容', max_length=500)
    read_time = DateTimeField("支付时间", default=None, null=True, blank=True)
    from_user = CharField('消息谁发的(具体)', max_length=500)
    message_type = IntegerField("消息类型(谁发的)", choices=MESSAGE_TYPE, default=1)
    add_time = DateTimeField('添加时间', default=datetime.now)

    class Meta:
        verbose_name = '用户消息'
        verbose_name_plural = verbose_name


class CourseComments(Model):
    is_del = IntegerField(default=0)
    # 这个评论部分,.为了防止恶意评论,采用了管理员审核的机制,所以有三种状态
    STATUS = (
        (1, '待审核'),
        (2, '通过'),
        (3, '不通过'),
    )
    user = ForeignKey(User, verbose_name='用户', on_delete=CASCADE)
    course = ForeignKey(Course, verbose_name='课程', on_delete=CASCADE)
    comments = CharField('评论', max_length=200)
    status = IntegerField(choices=STATUS,default=1)
    add_time = DateTimeField('添加时间', default=datetime.now)

    class Meta:
        verbose_name = '课程评论'
        verbose_name_plural = verbose_name



class UserCourse(Model):
    is_del = IntegerField(default=0)
    user = ForeignKey(User, verbose_name='用户', on_delete=CASCADE)
    course = ForeignKey(Course, verbose_name='课程', on_delete=CASCADE)
    IS_FINISHED = (
        (0,"未完成"),
        (1,"已完成"),
    )
    is_finished = IntegerField(choices=IS_FINISHED,default=0)
    add_time = DateTimeField('添加时间', default=datetime.now)
    class Meta:
        verbose_name = '用户课程'
        verbose_name_plural = verbose_name


class UserFavorite(Model):
    is_del = IntegerField(default=0)

    FAV_TYPE = (
        (1, '课程'),
        (2, '课程机构'),
        (3, '讲师')
    )
    user = ForeignKey(User, verbose_name='用户', on_delete=CASCADE)
    fav_id = IntegerField('数据id', default=0)
    fav_type = IntegerField(verbose_name='收藏类型', choices=FAV_TYPE, default=1)
    add_time = DateTimeField('添加时间', default=datetime.now)

    class Meta:
        verbose_name = '用户收藏'
        verbose_name_plural = verbose_name
